import time

import win32api
import win32con
import win32gui

from CaseAW.GridBase import winAppBase


class file_base(winAppBase):
    def windowsfileopen(self,classname,windowsname,absfilepath):
        self.driver.find_element_by_name("文件").click()
        self.driver.find_element_by_name("打开...").click()
        time.sleep(1)
        handle=win32gui.FindWindow(classname,windowsname)
        hwndChildlist=[]
        win32gui.EnumChildWindows(handle,lambda hwnd,param:param.append(hwnd),hwndChildlist)
        for index,hwnd in enumerate(hwndChildlist):
            classname=win32gui.GetWindowClassName(hwnd)
            text=win32gui.GetWindowText(hwnd)
            if text=="文件名(&N)":
                win32api.SendMessage(hwndChildlist[index+1],win32con.WM_SETTEXT,0,absfilepath)
                break
        time.sleep(0.5)
        self.driver.find_element_by_name("打开(O)").click()
        time.sleep(3)

